package main.social.web;

import javax.servlet.http.HttpServletRequest;

import main.social.service.AccountService;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "/Register")
public class RegisterController{

	protected final Log logger = LogFactory.getLog(getClass());
    private AccountService accountService;

    public void setAccountService(AccountService accountService) {
        this.accountService = accountService;
    }
    

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView register(HttpServletRequest request){
    	return new ModelAndView("Register");
    }
    
    @RequestMapping(method = RequestMethod.POST)
    public ModelAndView register_Submit(@RequestParam("username") String username, @RequestParam("password") String password,
    		@RequestParam("email") String email){
    	
		AccountService.Code result = this.accountService.insertAccount(username, password, email);
		switch(result){
			case UNHANDLE_ERROR: 
				return new ModelAndView("Success");
			case CONFLICT_USERNAME: 
				return new ModelAndView("Success");
			case CONFLICT_EMAIL: 
				return new ModelAndView("Success");
			default: 
				return new ModelAndView("Success");
		}
		
	}
}